<div class="center_content">
<form class="cmxform" id="form1" name="form1" method="post">
    <div class="content_c">
        <!--jquery validator显示错误信息的容器 -->
        <div class="serverErrorContainer" style="position:relative;">
            <div class="serverError">
                <ol>

                </ol>
            </div>

            <div class="container">
                <div class="searchButtonBox handleDiv" onclick="displayTable('handleDiv')">
                    <a href='javascript:void(0);' class="button switchOpen"  tabindex="-1" >
                        <div style="border:1px solid #96d0d2;border-bottom:0px;position:relative;float:right;cursor:pointer;">
                            <img id="handleDiv" src="./../theme/default/images/main/search/search_switch_open_normal.png" style="position:absolute;top:6px">
                            <input type="button" style="margin-top:0px;width:16px;">
                        </div>
                    </a>
                </div>
                <div id="handleDiv_child" class="errorDIv" divAttend="attend">
                    <ol>
                    </ol>
                </div>
            </div>
        </div>
        <!-- end -->
        <div id="hiddenDiv">
            <input type="hidden" id="functionId" name="function.id">
            <input type="hidden" id="taskStatus" name="taskStatus" <#if businessInstance?? && businessInstance.status?? && businessInstance.status.id??>value="${businessInstance.status.id}"</#if>>
            <input type="hidden" id="formId" name="form.id" <#if form?? && form.id??>value="${form.id}"</#if>>
            <input type="hidden" id="businessInstanceId" name="businessInstance.id" <#if businessInstance?? && businessInstance.id??>value="${businessInstance.id}"</#if>>
            <input type="hidden" id="businessInstanceIds" name="businessInstance.ids" <#if businessInstance?? && businessInstance.ids??>value="${businessInstance.ids}"</#if>>
        <#if businessInstance?? && businessInstance.parentInstance?? && (!businessInstance.id?? || (businessProcess.businessObj.isChild?? && businessProcess.businessObj.isChild=="1"))>
            <input type="hidden" id="parentInstanceId" name="parentInstance.id" value="${businessInstance.parentInstance.id}">
        </#if>
        <#if fieldMap??>
            <#list fieldMap?keys as key>
                <#if fieldMap[key].field??>
                    <input type=hidden name="fieldMap['${key}'].field.id" <#if fieldMap[key].field.id??> value="${fieldMap[key].field.id}"</#if>>
                    <input type=hidden id="${key}" name="fieldMap['${key}'].value" <#if fieldMap[key].value??> value="${fieldMap[key].value}"</#if>></input>
                    <input type=hidden id="${key}" name="fieldMap['${key}'].entityId" <#if fieldMap[key].entityId??> value="${fieldMap[key].entityId}"</#if>></input>
                </#if>
            </#list>
        </#if>
        </div>
        <table cellspacing="0" cellpadding="0" class="listviewTable" width="100%">
            <tbody>
            <tr height="0" style="border:0px">
                <td width="9%" style="border:0px"></td>
                <td width="25%" style="border:0px"></td>
                <td width="8%" style="border:0px"></td>
                <td width="25%" style="border:0px"></td>
                <td width="8%" style="border:0px"></td>
                <td width="25%" style="border:0px"></td>
            </tr>
            <#list group_list as item>
                <#if item.group?? && item.content?? && item.group.isShowTitle?default('1')=='1'>
                <tr class="listviewHeader">
                    <th colspan="6"  style="border-bottom:1px solid #c2e2eb;">
                        <div id="showYearFeeSpan" class="tableExtend tableOpen"></div>
                        <div style="float:left;line-height:17px;">
                            <span style="margin-left:10px;">${item.group.name}</span>
                        </div>


                    </th>
                </tr>
                </#if>
            ${item.content?default('')}
            </#list>

            <#list feature_list as feature>
                <#if 'planitem.planitem.clearimport'==feature.code>

                <tr>
                    <td  class="listviewTD" style="text-align:right;">是否清空导入:
                    </td>
                    <td  class="listviewContent" colspan="5">
                        <input id='clearImport' name="fieldMap['clearImport'].value" value=1 type='checkbox' style='float:left' />
                        <div id='tooptip' style='float:left; line-height:20px; display:none; color:red'>&nbsp;&nbsp;先清空该项目来源下的数据，再导入文件中的数据。</div>
                    </td></tr>
                </#if>
            </#list>




            </tbody>
        </table>
    </div>


    <div class="content_s layout_div">
        <div class="buttonBox">
            <a href="#" class="button" tabindex="-1">
                <input id="btnplanitem.planitem.import" type="button"  class="button" value="导入" onclick="processplanitem_form_TGridNet_N_0000012('planitem_function_a0000000000011','7','0','','0','','')"/>&nbsp;&nbsp;
            </a>


            <a href="#" class="button" tabindex="-1">
                <input id="btnplanitem.planitem.downLoad" type="button"  class="button" value="下载模板"    onclick="downLoadTemplate();return false;" />&nbsp;&nbsp;
            </a>
            <input type="hidden" id="importTemplateUrl" value="download/downLoadResourceFile?filename=planitem">

            <a href="#" class="button" tabindex="-1">
                <input id="btnplanitem.planitem.back3" type="button"  class="button" value="返回" onclick="processplanitem_form_TGridNet_N_0000012('planitem_function_00000000000777','4','0','','0','','')"/>&nbsp;&nbsp;
            </a>






        </div>












        <div id="importDiv" style="display:none;">
            <input type="hidden" name="fileInfo.realPath" id="realPath">
            <input type="hidden" name="fileInfo.realName" id="realName">
            <table cellspacing="0" cellpadding="0" width="240px" align="center">
                <tr class="listviewTR">
                    <td align="center" id="fileQueueTD" colspan="3">

                    </td>
                </tr>
                <tr class="listviewTR">
                    <td align="center" id="uploadifyTD">

                    </td>
                    <td align="center">
                        <a href="#" class="button"><input type="button"  class="button" onclick="cancelImport()" value="取消"></a>
                    </td>

                </tr>
            </table>
        </div>
    </div>
</form>
<div class="main_center_south_corner"></div>
<script type="text/javascript" src="./../script/page/config/formvalidate.js"></script>
<script type="text/javascript" src="./../script/page/config/tdqs.validate.js"></script>
<script language="javascript">


function importData() {

            var div = document.createElement('div');
            div.id='fileQueue';
            $(div).css('text-align','left');
            $('#fileQueueTD').append($(div));
            var input = document.createElement('input');
            input.type='file';
            input.name='importUploadify';
            input.id='importUploadify';
            $('#uploadifyTD').append(input);
            $('#importUploadify').uploadify({
                'basepath'       : TDQS.CONTEXT_PATH,
                'queueID'        : "fileQueue",
                'fileDesc' :  '请选择文件',
                'multi' : false,
                'sizeLimit' :1024*1024*50,
                'fileExt' :'*.xls;*.xlsx;',
                'onComplete':function(event, ID, fileObj, response, data){
                    var result = $.parseJSON(response);
                    $('#realPath').val(result.realPath);
                    $('#realName').val(encodeURI(result.realName));
                    executeImport();
                    //$('#importUploadify').uploadifyClearQueue();
                    document.getElementById("fileQueue").innerHTML ="";
                    $('#fileQueue').remove();
                    $('#importUploadify').remove();
	      },
	      'onCancel':function(){
			cancelImport();
	      },
	      'onError':function(){
			cancelImport();
                }
            });
            $.blockUI({message:$('#importDiv')});
      
}
function cancelImport() {
    $.unblockUI();
    $('#fileQueue').remove();
    $('#importUploadify').remove();
}

function showUrl(url) {
    url = TDQS.CONTEXT_PATH+ encodeURI(url);
    if(url.indexOf('?')==-1) {
        url += '?';
    } else {
        url += '&';
    }
    url += 'date='+new Date().toLocaleString();
    postForm(url);
}

function downLoadTemplate() {
    var url = $('#importTemplateUrl').val();
    if(url!='') {
        showUrl(url);
    }
}

function downLoadImportFile(fileName) {
    var url = TDQS.CONTEXT_PATH+"/download/downLoadImportFile?filename="+fileName+"&date="+new Date().toLocaleString();
    var frame = document.createElement("iframe");
    frame.src = url;
    frame.style.display = "none";
    document.body.appendChild(frame);
}
function executeImport() {

    $.unblockUI();

    var url = TDQS.CONTEXT_PATH+"business/process?tdqssid="+TDQS.SESSION_ID+"&fileInfo.realPath="+$('#realPath').val()+"&fileInfo.realName="+$('#realName').val();

    blockProcess($('.bodyClass'),"导入进度：");
    var interval = setInterval(function(){
        $.tdqsAjax({
            type : "post",
            url : TDQS.CONTEXT_PATH+'user/percent',// 目标地址
            success : function(json) {
                setblockProcess(json.data);
                if(json.data=='100'){
                    unblockProcess();
                    clearInterval(interval);
                }
            }
        });

    },500);
    $.tdqsAjax({
        type: "post",
        dataType: "json",
        data: $('#form1').serialize(),
        url: url,
        success:function(json) {
            setblockProcess(100);
            unblockProcess();
            clearInterval(interval);
            if(json.data && json.data.type && json.data.type=='2' && json.data.resultData){
                var message = json.data.resultData;
                if(message.indexOf(".xls")>-1 || message.indexOf(".xlsx")>-1) {
                    message = "导入文件存在错误的数据，请下载文件后重新修改并导入！<a href=\"javascript:void(0);\" onclick=\"downLoadImportFile('"+encodeURI(message)+"');return false;\">下载</a>";
                }
                jAlert(message,'提示',function(){

                });
            }
            else {

                $(document.getElementById("btnplanitem.planitem.back3")).click();
            }

        }
    });

}

$(function(){



    $("#clearImport").click(function(){


        if($("#tooptip").css("display")=='none') {
            $("#tooptip").show();
        }
        else{
            $("#tooptip").hide();
        }

    })







    layout();
    $("#form1 .tableExtend").each(function(i){
        $(this).click(function(){
            var objHeard = $(this);
            var currentTR = $($(this).parents("tr").get(0));

            $(currentTR).addClass("selectedExtendTr");
            var objTbody = $($(this).parents("tbody").get(0));
            var jud= false;
            var trColle = $(">tr",objTbody);
            for(var i=0;i<trColle.length;i++){
                if($(trColle[i]).hasClass("selectedExtendTr")){
                    jud = true;
                    continue;
                }else{
                    if(!jud){
                        continue;
                    }
                }

                if($(trColle[i]).hasClass("listviewHeader") && jud == true){
                    if($(objHeard).hasClass("tableOpen")){
                        $(objHeard).removeClass("tableOpen");
                        $(objHeard).addClass("tableClose");

                    }else{
                        $(objHeard).removeClass("tableClose");
                        $(objHeard).addClass("tableOpen");
                    }

                    break;
                }
                if($(objHeard).hasClass("tableOpen")) {
                    if(i == trColle.length-1){
                        $(objHeard).removeClass("tableOpen");
                        $(objHeard).addClass("tableClose");
                    }
                    $(trColle[i]).hide();
                } else {
                    if(i == trColle.length-1){
                        $(objHeard).removeClass("tableClose");
                        $(objHeard).addClass("tableOpen");
                    }
                    $(trColle[i]).show();
                }
            }
            $(currentTR).removeClass("selectedExtendTr");
        })
    })

    $('table[tabletype="datagrid"]').each(function(){
        eval('gotoGrid'+$(this).attr('field')+'()');
    });
});

function layout(){
    var toggle_we        = '<div class="btnToggler_we"></div>'
            , toggle_w        = '<div class="btnToggler_w"></div>'
            ;
    $('body').layout({
        center__paneSelector:   ".center_content"
        ,    south__paneSelector:    ".main_center_south_corner"
        ,    south__size:    10
        ,    south__spacing_open:    0
        ,    south__spacing_close:    0
        ,    south__closable:    false
        ,    south__resizable:    false
    });

    $(".main_center_south_corner").css({overflow:"hidden"});
    $(".center_content").css({"overflow-x":"auto"});
    $(".center_content").css({"overflow-y":"auto"});

    var contentLayout = $('div.center_content').layout({
        center__paneSelector:    ".content_c"
        ,    south__paneSelector:    ".content_s"
        ,    south__size:    40
        ,    south__spacing_open:    0
        ,    south__spacing_close:    0
        ,    south__closable:    false
        ,    south__resizable:    false

    });
    $(".content_s").css({overflow:"auto"});
}

var validator;
var origFuncId;
function process${form.id}(funcId,type,messageType,message,clearSession,logicMessage,logicBranchFuncId) {

    if(type =='7'){
        $('#functionId').val(funcId);
        importData();
        return;
    }



    var validteType =type;
    if(type =='5'){
        type ='3';
    }

    if(validator && type == '3') {
        validator.type =validteType;
        if(!validator.form()) {
            //HotFirstErrorMessage();
            return false;
        }
    }

    var url = TDQS.CONTEXT_PATH+'business/process';
    if(!message||message=='') {
        message = '确定要执行操作吗？';
    }

    if(messageType && messageType=='1') {

        jConfirm(message, '确认对话框 ', function(r) {
            if(r){
                if(logicMessage && logicMessage!='' && logicBranchFuncId && logicBranchFuncId!='') {
                    jYesOrNoConfirm(logicMessage, '确认对话框 ', function(r) {
                        if(!r) {
                            funcId = logicBranchFuncId;
                        }
                        if(type && type=='3') {
                            if(clearSession=='1') {
                                url += '?clearSession='+clearSession+'&tdqssid='+TDQS.SESSION_ID;
                            }
                        ${"$('#functionId')"}.val(funcId);
                        ${"$('#form1')"}.attr('action',url);
                        ${"$('#form1')"}.submit();
                        } else if(type && type=='6') {
                        ${"$('#functionId')"}.val(funcId);
                            exportData();
                        } else {
                            url += "?tdqssid="+TDQS.SESSION_ID+"&function.id="+funcId+"&businessInstance.id="+$('#businessInstanceId').val()+"&taskStatus="+$('#taskStatus').val()+"&form.id="+$('#formId').val();
                        <#if businessInstance?? && businessInstance.parentInstance?? && (!businessInstance.id?? || (businessProcess.businessObj.isChild?? && businessProcess.businessObj.isChild=="1"))>
                            url += "&parentInstance.id="+$('#parentInstanceId').val();
                        </#if>
                            if(clearSession=='1') {
                                url += '&clearSession='+clearSession;
                            }
                            url += "&date="+new Date().toLocaleString();
                            document.location.href = url;
                        }
                    });
                } else {
                    if(type && type=='3') {
                        if(clearSession=='1') {
                            url += '?clearSession='+clearSession+"&tdqssid="+TDQS.SESSION_ID;
                        }
                    ${"$('#functionId')"}.val(funcId);
                    ${"$('#form1')"}.attr('action',url);
                    ${"$('#form1')"}.submit();
                    } else if(type && type=='6') {
                    ${"$('#functionId')"}.val(funcId);
                        exportData();
                    } else {
                        url += "?tdqssid="+TDQS.SESSION_ID+"&function.id="+funcId+"&businessInstance.id="+$('#businessInstanceId').val()+"&taskStatus="+$('#taskStatus').val()+"&form.id="+$('#formId').val();
                    <#if businessInstance?? && businessInstance.parentInstance?? && (!businessInstance.id?? || (businessProcess.businessObj.isChild?? && businessProcess.businessObj.isChild=="1"))>
                        url += "&parentInstance.id="+$('#parentInstanceId').val();
                    </#if>
                        if(clearSession=='1') {
                            url += '&clearSession='+clearSession;
                        }
                        url += "&date="+new Date().toLocaleString();
                        document.location.href = url;
                    }
                }
            }else{
                return false;
            }
        });
    } else {
        if(type && type=='3') {
            if(clearSession=='1') {
                url += '?clearSession='+clearSession+"&tdqssid="+TDQS.SESSION_ID;
            }
        ${"$('#functionId')"}.val(funcId);
        ${"$('#form1')"}.attr('action',url);
        ${"$('#form1')"}.submit();
        } else if(type && type=='6') {
        ${"$('#functionId')"}.val(funcId);
            exportData();
        } else if(type && type=='4') {
            $('#functionId').val(origFuncId);
            if(serializeformData == $("#form1").serialize()){
                $('#functionId').val(funcId);
                url += "?tdqssid="+TDQS.SESSION_ID+"&function.id="+funcId+"&businessInstance.id="+$('#businessInstanceId').val()+"&taskStatus="+$('#taskStatus').val()+"&form.id="+$('#formId').val();
            <#if businessInstance?? && businessInstance.parentInstance?? && (!businessInstance.id?? || (businessProcess.businessObj.isChild?? && businessProcess.businessObj.isChild=="1"))>
                url += "&parentInstance.id="+$('#parentInstanceId').val();
            </#if>
                if(clearSession=='1') {
                    url += '&clearSession='+clearSession;
                }
                url += "&date="+new Date().toLocaleString();
                document.location.href = url;
            }else{
                $('#functionId').val(funcId);

                url += "?tdqssid="+TDQS.SESSION_ID+"&function.id="+funcId+"&businessInstance.id="+$('#businessInstanceId').val()+"&taskStatus="+$('#taskStatus').val()+"&form.id="+$('#formId').val();
            <#if businessInstance?? && businessInstance.parentInstance?? && (!businessInstance.id?? || (businessProcess.businessObj.isChild?? && businessProcess.businessObj.isChild=="1"))>
                url += "&parentInstance.id="+$('#parentInstanceId').val();
            </#if>
                if(clearSession=='1') {
                    url += '&clearSession='+clearSession;
                }
                url += "&date="+new Date().toLocaleString();
                document.location.href = url;


            }
        } else {
            url += "?tdqssid="+TDQS.SESSION_ID+"&function.id="+funcId+"&businessInstance.id="+$('#businessInstanceId').val()+"&taskStatus="+$('#taskStatus').val()+"&form.id="+$('#formId').val();
        <#if businessInstance?? && businessInstance.parentInstance?? && (!businessInstance.id?? || (businessProcess.businessObj.isChild?? && businessProcess.businessObj.isChild=="1"))>
            url += "&parentInstance.id="+$('#parentInstanceId').val();
        </#if>
            if(clearSession=='1') {
                url += '&clearSession='+clearSession;
            }
            url += "&date="+new Date().toLocaleString();
            document.location.href = url;
        }
    }
}

function exportData() {
    $('#exportFrame').remove();
    var frame = document.createElement('iframe');
    frame.id='exportFrame';
    frame.name='exportFrame';
    frame.style.display='none';
    document.body.appendChild(frame);
    var doc = document.getElementById('exportFrame').contentWindow.document;
    doc.write('<html><body></body></html>');
    var form = doc.createElement("form");
    form.action=TDQS.CONTEXT_PATH+'business/process?tdqssid='+TDQS.SESSION_ID;
    $(form).attr('method','post');
    var div = doc.createElement("div");
    div.style.display = "none";
    div.innerHTML=$('#hiddenDiv').html();
    $(form).append(div);
    doc.body.appendChild(form);
    form.submit();
}

<#if form.validation??>
${form.validation}
</#if>
<#if form.script??>
${form.script}
</#if>

$(function() {
    serializeformData=$("#form1").serialize();
    left_current_page = true;
    origFuncId = $('#functionId').val();
});

</script>